<template>
  <div>
    <div class="crumbs">
      <el-breadcrumb separator="/">
        <el-breadcrumb-item>
          <i class="el-icon-lx-shop"></i> 商城分类
        </el-breadcrumb-item>
      </el-breadcrumb>
    </div>
    <div class="container">
      <div class="handle-box">
        <el-input v-model="searchName" placeholder="分类名称" class="handle-input mr10" width="55"></el-input>
        <el-button type="primary" icon="el-icon-search" @click="handleSearch">搜索</el-button>
        <el-button type="primary" icon="el-icon-lx-friendadd" @click="showBox()">添加分类</el-button>
      </div>
      <el-table :data="tableData" border class="table" ref="multipleTable" header-cell-class-name="table-header">
        <el-table-column prop="applyMobile" label="申请人手机号"></el-table-column>
        <el-table-column prop="createTime" label="创建时间" :formatter="dateFormat"></el-table-column>
        <el-table-column label="退款状态" align="center" width="100">
          <template #default="scope">
            <el-tag v-if="scope.row.status == '1'">审核中</el-tag>
            <el-tag v-if="scope.row.status == '2'">同意</el-tag>
            <el-tag v-if="scope.row.status == '3'">拒绝</el-tag>
          </template>
        </el-table-column>
        <el-table-column prop="noReason" label="拒绝理由"></el-table-column>
        <el-table-column prop="orderNo" label="订单编号"></el-table-column>
        <el-table-column prop="reason" label="退款理由"></el-table-column>
        <el-table-column prop="refundDeal" label="退款交易流水号"></el-table-column>
        <el-table-column prop="refundIntegral" label="退款积分"></el-table-column>
        <el-table-column prop="refundMoney" label="退款金额"></el-table-column>
        <el-table-column label="退款图片1"> <template #default="scope"> <el-image class="table-td-thumb" :src="scope.row.reasonImg1"></el-image> </template> </el-table-column>
        <el-table-column prop="classifySort" label="排序字段"></el-table-column>
        <el-table-column prop="createTime" label="创建时间" :formatter="dateFormat"></el-table-column>
        <el-table-column prop="refundTime" label="退款时间" :formatter="dateFormat"></el-table-column>
        <el-table-column label="操作" width="180" align="center">
          <template #default="scope">
            <el-button type="text" @click="agree(scope.row)" v-if="scope.row.status == '1'">同意</el-button>
            <el-button type="text" @click="refuse(scope.row)" v-if="scope.row.status == '1'">拒绝</el-button>
          </template>
        </el-table-column>
      </el-table>
      <div class="pagination">
        <el-pagination background layout="total, prev, pager, next" :current-page="query.pageIndex" :page-size="query.pageSize" :total="pageTotal" @current-change="handlePageChange"></el-pagination>
      </div>
    </div>

  </div>
</template>

<script>
import { refundList, } from "../../api/zyMall";
import { api, } from "../../api/index";
import { formatDate } from "../../common/data";
import moment from "moment";
export default {
  inject: ["reload"],
  filters: {
    formatDate(time) {
      time = time * 1000;
      let date = new Date(time);
      console.log(new Date(time));
      return formatDate(date, "yyyy-MM-dd hh:mm");
    },
  },
  name: "basetable",
  data() {
    return {
      query: {
        pageNo: 1,
      },
      searchName: "",
      tableData: [],
      // multipleSelection: [],
      showAddUser: false,
      pageTotal: 0,
      classlist: {
        classifyName: "",
        classifyPic: "",
        classifyPid: "",
        classifySort: 1,
      },
      classSonList: {},
      isChange: "",
    };
  },
  created() {
    this.getData();
  },
  mounted() { },
  methods: {
    dateFormat: function (row, column) {
      var date = row[column.property];
      if (date == undefined) {
        return "";
      }
      return moment(date).format("YYYY-MM-DD HH:mm:ss");
    },

    // 获取分类列表
    getData() {
      refundList({
        applyMobile: this.searchName,
        status: "",
        limit: 10,
        offset: this.query.pageNo,
      }).then((res) => {
        // console.log(res.data);
        this.tableData = res.data.rows;
        this.pageTotal = res.data.total;
      });
    },

    //显示编辑框
    showBox() {
      this.showAddUser = true;
      this.isChange = 1;
    },
    // 触发搜索按钮
    handleSearch() {
      this.getData();
    },

    // 分页导航
    handlePageChange(val) {
      // console.log(val);
      this.query.pageNo = val;
      this.getData();
    },
    agree(row) {
      this.$confirm("确定同意退款吗？", "提示", { type: "warning", }).then(() => {
        api('/web/sar/ok', { id: row.id, remark: '1', refundType: '2' }).then((res) => {
          if (res.code === 2000) {
            this.$message.success(res.message);
            this.reload()
          } else {
            this.$message.error(res.message);
          }
        });
      }).catch(() => { });
    },
    refuse(row) {
      this.$prompt("(拒绝理由)", "确定拒绝此订单退款！", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
      }).then(({ value }) => {
        api('/web/sar/no', { id: row.id, noReason: value ? value : "", remark: '1', }).then((res) => {
          if (res.code === 2000) {
            this.$message.success(res.message);
            this.reload();
          } else {
            this.$message.error(res.message);
          }
        });
      })
    },
  },
};
</script>

<style lang='scss' scoped>
.handle-box {
  margin-bottom: 20px;
}

.handle-select {
  width: 120px;
}

.handle-input {
  width: 300px;
  display: inline-block;
}

.table {
  width: 100%;
  font-size: 14px;
}

.red {
  color: #ff0000;
}

.mr10 {
  margin-right: 10px;
}

.table-td-thumb {
  display: block;
  margin: auto;
  width: 40px;
  height: 40px;
}

.crop-demo {
  display: flex;
  align-items: flex-end;
  border: 1px dashed #d9d9d9;
  border-radius: 6px;
  width: 178px;
  height: 178px;

  .pre-img {
    width: 178px;
    height: 178px;
    background: #f8f8f8;
    border: 1px solid #eee;
    border-radius: 5px;
    object-fit: cover;
  }

  .crop-input {
    position: absolute;
    width: 178px;
    height: 178px;
    left: 0px;
    top: 0px;
    opacity: 0;
    cursor: pointer;
  }

  .avatar-uploader-icon {
    font-size: 28px;
    color: #8c939d;
    width: 178px;
    height: 178px;
    line-height: 178px;
    text-align: center;
  }
}
</style>
